package com.itcam.tingshu.user.strategy.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itcam.tingshu.model.user.UserPaidAlbum;
import com.itcam.tingshu.user.mapper.UserPaidAlbumMapper;
import com.itcam.tingshu.user.strategy.PaymentStrategy;
import com.itcam.tingshu.vo.user.UserPaidRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : Cammy.Wu
 * Description : 
 */

@Service("albumPaymentStrategy")
public class AlbumPaymentStrategy implements PaymentStrategy {

    @Autowired
    private UserPaidAlbumMapper userPaidAlbumMapper;

    /**
     * 购买专辑记录
     * @param userPaidRecordVo
     */
    @Override
    public void processPayment(UserPaidRecordVo userPaidRecordVo) {
// 根据订单编号查询是否有当前订单 select*from user_paid_album where order_no = ?
        UserPaidAlbum userPaidAlbumQuery = userPaidAlbumMapper.selectOne(new LambdaQueryWrapper<UserPaidAlbum>());
        if (userPaidAlbumQuery != null) return;
        // 购买专辑 user_paid_album
        UserPaidAlbum userPaidAlbum = new UserPaidAlbum();
        // 赋值
        userPaidAlbum.setOrderNo(userPaidRecordVo.getOrderNo());
        userPaidAlbum.setUserId(userPaidRecordVo.getUserId());
        userPaidAlbum.setAlbumId(userPaidRecordVo.getItemIdList().get(0));
        // 保存
        userPaidAlbumMapper.insert(userPaidAlbum);
    }
}
